Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add http route to outgoing http requests, if available #5129

Closed

Conversation

klippx
Copy link

@klippx klippx commented Nov 8, 2024

Which problem is this PR solving?

We have a large mono repo and our app users have the need for the following usage:

  new HttpInstrumentation({
    startOutgoingSpanHook(request) {
      const headers = request.headers ?? {};
      if ('x-otel-path-template' in headers) {
        return {
          [SEMATTRS_HTTP_ROUTE]: headers['x-otel-path-template'], // A path template, e.g. `/users/{id}` or `/blog/{blogId}/posts/{postId}`
        };
      }
      return {};
    },
  }),

Since our users are tracking SLOs for their services for different endpoints, they need histograms observations to include the path tempate. This path template comes from mappersmith and we take care of setting it ourselves, as can be seen above. Yes, it is a bit hacky, this path template is sent via a header, but that's our problem. 😬 It's good enough for us for now at least.

But we need to patch opentelemetry to read it and put it in the histogram observation, hence the PR.

Short description of the changes

Ensure that 'http.route' makes it to metric attributes, if it is available from the span attribute.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

I hesitate to check breaking. If someone today is also setting SEMATTRS_HTTP_ROUTE in startOutgoingSpanHook and NOT expecting it to result in a new label in prometheus metrics, I guess that's a unexpected. But not breaking.

How Has This Been Tested?

We have had this code running in production for 1 month.

  • Added tests, see PR diff

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@klippx klippx marked this pull request as ready for review November 8, 2024 15:19
@klippx klippx requested a review from a team as a code owner November 8, 2024 15:19
@pichlermarc
Copy link
Member

Hi @klippx thanks for reaching out - the feature in this PR is essentially #5051 which will not be accepted unless #4095 and #4096 are addressed. This feature (as it stands without these two issues addressed) is very likely introduce severe memory issues if used incorrectly. Therefore I have to reject this PR.

Someone is already working on #4095 and #4096 is open for contributions. We will then go ahead with a hook as outlined in #5051 which should also address your requirements IIUC.

@pichlermarc pichlermarc closed this Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants